#include "fxcc/json/Serializer.h"

using namespace fxcc::json;

struct User
{
	int m_No;
	float m_Value;
	std::string m_Name;
	std::string m_Password;
	std::vector<int> m_Childrens;
	std::map<std::string, std::string> m_Datas;


};
template<>
void Serializer::Encode<User>(nlohmann::json& j, const User& e)
{
	SetVariable<int>(j, "m_No", e.m_No);
	SetVariable<float>(j, "m_Value", e.m_Value);
	SetVariable<std::string>(j, "m_Name", e.m_Name);
	SetVariable<std::string>(j, "m_Password", e.m_Password);
	SetArrayVariable<int>(j, "m_Children", e.m_Childrens);
	SetMapVariable<std::string>(j, "m_Datas", e.m_Datas);
}

template<>
bool Serializer::Decode<User>(const nlohmann::json& j, User& e)
{
	GetVariable<int>(j, "m_No", e.m_No);
	GetVariable<float>(j, "m_Value", e.m_Value);
	GetVariable<std::string>(j, "m_Name", e.m_Name);
	GetVariable<std::string>(j, "m_Password", e.m_Password);
	GetArrayVariable<int>(j, "m_Children", e.m_Childrens);
	GetMapVariable<std::string>(j, "m_Datas", e.m_Datas);
	return true;
}


int main()
{
	User user;
	User user2;
	user.m_No = 20;
	user.m_Value = 200.f;
	user.m_Name = "fbz doc";
	user.m_Password = "123465";
	user.m_Childrens = { 1,2,3, 4 };
	user.m_Datas = {

		{"left1", "left1_value"},
		{"left2", "left2_value"},
		{"left4", "left4_value"},
	};

	json j2;
	Serializer jsonser;
	jsonser.EncodePath<User>("demo2.json", user);
	jsonser.DecodePath<User>("demo2.json", user2);

	//json j;
	//jsonser.Encode<User>(j, user);

	//std::cout << j.dump() << std::endl;

	//User user2;
	//jsonser.Decode<User>(j, user2);


	return 0;
};